const app = getApp();
Page({
  data:{
    pages:0,
    consultList: [],
    specialtyList: [],
    url: '',
    pageNum:1,
    isLoading:false
  },
  getData(){
    wx.showLoading({
      title:'正在加载中...',
      icon:'loading',
      mask:true
    });
    this.setData({
      url: app.globalData.URL,
      isLoading:true
    })
    let that = this;
    wx.request({
      url: that.data.url + 'consultspecialty/selectByPage',
      data:{
        pageNum:that.data.pageNum,
        pageSize:30
      },
      method: 'GET',
      success(resp) {
        that.setData({
          specialtyList: [...that.data.specialtyList,...resp.data.data.list],
          pages:resp.data.data.pages,
        })
        console.log(that.data.specialtyList);
      },
      complete(){
        wx.hideLoading();
        wx.stopPullDownRefresh();
        that.setData({
          isLoading:false
        })
      }
    })
        wx.request({
          url: that.data.url + 'consult/findAll',
          data:{
            pageNum:that.data.pageNum,
            pageSize:8
          },
          method: 'GET',
          success(resp) {
            that.setData({
              consultList: [...that.data.consultList,...resp.data.data.list],
              pages:resp.data.data.pages,
            })
          },
          complete(){
            wx.hideLoading();
            wx.stopPullDownRefresh();
            that.setData({
              isLoading:false
            })
          }
        })
  },
  onPullDownRefresh() {
    this.setData({
      consultList:[],
      specialtyList: [],
      pageNum:1,
      pages:0
    })
    this.getData();
  },
  onReachBottom() {
    if(this.data.isLoading){
      return;
    }
    this.setData({
      pageNum:this.data.pageNum+1,
    })
    if(this.data.pageNum>this.data.pages){
      wx.showToast({
        title: '没有更多数据了......',
      })
      return;
    }
    this.getData();
  },
  onClickLeft(){
      wx.navigateBack();
  },
  onLoad:function(){
    this.getData();
  },
  onShow:function(){
    
  }
})
